package oop.core.med;
import oop.core.Scheduler;
import oop.core.Updateable;
import oop.core.entity.*;
import oop.core.map.*;
import oop.core.item.*;
import java.util.*;

public class NPCMovementMediator extends EntityMovementMediator 
{
	private NPC npc;
	private Scheduler scheduler;
	
	public NPCMovementMediator(NPC npc, GameMap gameMap, MovementLogic movementLogic, Scheduler scheduler)
	{
		super(gameMap,movementLogic);
		this.scheduler = scheduler;
		super.canMove = false;
	}
	
	public void moveEntity(int direction)
	{
		Location npcLocation;
		Location newLocation;
		List<MovementType> movementType;
		

		npcLocation = npc.getLoc();
		movementType = npc.getMovementTypes();

		npc.setDirection(direction);

		// return a location to move to
		// otherwise, return null
		boolean delayed = npc.getDelayFlag();
		
		if(super.canMove && !delayed)
		{
			newLocation = movementLogic.move(movementType, npcLocation, direction);
			if(newLocation != null)
			{
				npc.setLoc(newLocation);
				super.canMove = false;
				long delayTotal = 1000 / npc.getMovementSpeed();
				scheduler.register(this, delayTotal);
			}
		}	
	}
	public boolean getCanMove(){
		return super.canMove;
	}

	public NPC getNpc() {
		return npc;
	}

	public void setNpc(NPC npc) {
		this.npc = npc;
	}

	public Scheduler getScheduler() {
		return scheduler;
	}

	public void setScheduler(Scheduler scheduler) {
		this.scheduler = scheduler;
	}
}
